exports.lexer   = require('./lexer')

exports.parser  = require('./parser')

exports.nodes   = require('./nodes')

exports.parse = (sql) -> exports.parser.parse(exports.lexer.tokenize(sql))

exports.parse2 = (sql, opts) ->
  
  tokenInfo = exports.lexer.tokenize2(sql, opts)
  tokens = tokenInfo.tokens
  placeholders = tokenInfo.placeholders
  paramsLength = placeholders.length
  args = opts.args or []
  
  return exports.parser.parse(tokens) if paramsLength < 1 and args.length < 1

  exports.parser.throwUnMatchedParamsExc() if args.length > 0 and paramsLength < 1
  
  opts.placeholders = placeholders
  
  return exports.parser.parse2(tokens, opts)